package sysmng.data
{
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	public class SysmngQuery
	{
		private var remoteObject:RemoteObject
		
		public var onReceive_GetUserInfoList:Function;
		public var onReceive_GetUserBaseInfo:Function;
		public var onReceive_DeleteUserBaseInfo:Function;
		public var onReceive_GetRoleInfoList:Function;
		public var onReceive_DeleteRoleBaseInfo:Function;
		public var onReceive_EditUserInfo:Function;
		public var onReceive_EditRoleInfo:Function;
		public var onReceive_GetMenuList:Function;
		public var onReceive_GetRoleBaseInfo:Function;
		
		
		public var onErrorFunction:Function;
		
		public function SysmngQuery()
		{
			remoteObject  = new RemoteObject("fluorine");
			remoteObject.source = "Sysmng.SysmngQuery";
			
			remoteObject.GetUserBaseInfo.addEventListener("result",GetUserBaseInfo_ResultHandler);
			remoteObject.GetUserInfoList.addEventListener("result",GetUserInfoList_ResultHandler);
			remoteObject.DeleteUserBaseInfo.addEventListener("result",DeleteUserBaseInfo_ResultHandler);
			remoteObject.GetRoleInfoList.addEventListener("result",GetRoleInfoList_ResultHandler);
			remoteObject.DeleteRoleBaseInfo.addEventListener("result",DeleteRoleBaseInfo_ResultHandler);
			remoteObject.EditUserInfo.addEventListener("result",EditUserInfo_ResultHandler);
			remoteObject.EditRoleInfo.addEventListener("result",EditRoleInfo_ResultHandler);
			remoteObject.GetMenuList.addEventListener("result",GetMenuList_ResultHandler);
			remoteObject.GetRoleBaseInfo.addEventListener("result",GetRoleBaseInfo_ResultHandler);
			
		
			remoteObject.addEventListener("fault", onFault);
			
			onReceive_GetUserInfoList = null;
			onReceive_GetUserBaseInfo = null;
			onReceive_DeleteUserBaseInfo = null;
			onReceive_GetRoleInfoList = null;
			onReceive_DeleteRoleBaseInfo = null;
			onReceive_EditUserInfo = null;
			onReceive_EditRoleInfo = null;
			onReceive_GetMenuList = null;
			onReceive_GetRoleBaseInfo = null;
			onErrorFunction = null;
		}
		
		//====================
		public function GetUserInfoList(searchType:int,searchContent:String
										,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetUserInfoList(searchType,searchContent);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetUserInfoList_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetUserInfoList)
				onReceive_GetUserInfoList(event.result);
		}
		
		//====================
		public function GetRoleInfoList(searchContent:String
										,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetRoleInfoList(searchContent);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetRoleInfoList_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetRoleInfoList)
				onReceive_GetRoleInfoList(event.result);
		}
		
		//====================
		public function GetUserBaseInfo(responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetUserBaseInfo();
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetUserBaseInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetUserBaseInfo)
				onReceive_GetUserBaseInfo(event.result);
		}
		
		//====================
		public function DeleteUserBaseInfo(rst:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteUserBaseInfo(rst);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteUserBaseInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteUserBaseInfo)
				onReceive_DeleteUserBaseInfo(event.result);
		}
		
		//====================
		public function DeleteRoleBaseInfo(role_id:int,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteRoleBaseInfo(role_id);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteRoleBaseInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteRoleBaseInfo)
				onReceive_DeleteRoleBaseInfo(event.result);
		}
		
		//====================
		public function EditUserInfo(userInfoItem:UserInfoItem,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.EditUserInfo(userInfoItem);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function EditUserInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_EditUserInfo)
				onReceive_EditUserInfo(event.result);
		}
		
		//====================
		public function EditRoleInfo(roleInfoItem:RoleInfoItem,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.EditRoleInfo(roleInfoItem);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function EditRoleInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_EditRoleInfo)
				onReceive_EditRoleInfo(event.result);
		}
		
		//====================
		public function GetMenuList(responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetMenuList();
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetMenuList_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetMenuList)
				onReceive_GetMenuList(event.result);
		}
		
		//====================
		public function GetRoleBaseInfo(role_id:int,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetRoleBaseInfo(role_id);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetRoleBaseInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetRoleBaseInfo)
				onReceive_GetRoleBaseInfo(event.result);
		}

		//=========================
		public function onFault (event:FaultEvent):void
		{
			if(onErrorFunction!=null)
			{
				onErrorFunction();
			}
			else
			{
				Alert.show(event.fault.faultString, "Error");
			}
		}
	}
}